Repository navigation
fix(cli): create --template shows the fields a create writes in a KB (#1598) - #1605
swastiktawate wants to merge 1 commit into
Conversation
…yrite-wiki#1598) The template skeleton came from the core types only, so a backlog_item skeleton had none of the fields a real create writes, and a type the KB does not declare was not refused. With -k, the skeleton now reads the same place a create does: KBService.create_template_fields builds the entry the way _prepare builds one and reads its declared frontmatter. Without -k, the skeleton is unchanged.
markramm
left a comment
There was a problem hiding this comment.
Automated review by the maintainer's conductor agent, of head 1e2af296: a cold read of the diff by a separate reader (read-only), then each item below re-run by the conductor in its own throwaway KBs. This touches pyrite/services/kb_service.py and what a CLI command answers, so the maintainer merges it.
Thank you: this does what the groom on #1598 asked. The refusals come from the same code a create uses (the JSON envelopes and exit codes are identical for an undeclared type and for an unknown -k), --template writes nothing (file hashes unchanged), the backlog_item skeleton equals a real create's frontmatter, and the output without -k is the old code unchanged. Three things stand between this and a merge. Items 2 and 3 are regimes the groom did not name; that gap is ours, not yours.
1. tests/test_create_template_kb.py: CI is red on tests/test_production_wiring_guard.py::test_no_file_adds_a_site ("3 load_config site(s), baseline 0"; ran it). The three sites are patch("pyrite.config.load_config") in the software_kb fixture (line 37) and the two patches in _patch_config (lines 59-60). Delete software_kb, _patch_config and init_app, and use the cli_world fixture from tests/conftest.py, which runs the real load_config against a throwaway config:
def test_template_backlog_item_matches_real_create(cli_world, tmp_path):
world = cli_world()
assert world.cli("init", "--template", "software", "--path", str(tmp_path / "proj"),
"--name", "proj", "--no-examples").exit_code == 0
world.cli("create", "-k", "proj", "-t", "backlog_item", "--title", "x")
result = world.cli("create", "-k", "proj", "-t", "backlog_item", "--template", "--format", "json")
# compare result's frontmatter with the file the create wrote2. KBService.create_template_fields and test_template_undeclared_type_allowed_with_flag: a create that is refused still gets a skeleton. In a KB from pyrite init --template software (ran both):
create -k proj -t nosuch --template --allow-undeclaredprints a skeleton, exit 0;create -k proj -t nosuch --title nz --allow-undeclaredis refused, exit 1, ruleknown_type(that KB hasvalidation.enforceon).
The test pins the first and never runs the second. Make the skeleton answer what the create answers here, and rewrite the test to run the real create with the same flags and compare the two outcomes.
3. KBService.create_template_fields: the type is not resolved the way _prepare resolves it. _prepare calls _resolve_entry_type (line 1594) and _refuse_undeclared_mapping_target; the new method skips both. In a KB with kb_type: journalism-investigation and no types: in kb.yaml (ran both):
create -k inv2 -t event --templateprintstype: eventwithlocationandactors;create -k inv2 -t event --title e1 -d 2024-01-01writestype: investigation_eventwithverification_status: unverified, and nolocationoractors.
Resolve the type with the same two calls before building, put the resolved type in the skeleton, and add that KB as a test case. Please do not restructure _prepare itself: #1601 is changing that function now, so keep your edit to the new method and merge dev after #1601 lands (one small conflict at most).
Smaller, same push if you can:
- One parametrised test over (KB, type, flags) that runs a real
create --title x, reads the file and compares its frontmatter with the skeleton (apart fromid,title,tags), or compares the two error envelopes when both refuse. Today onlybacklog_itemis compared with a real create; theseverity == "low"case is a value written by hand. That one test would have caught items 2 and 3. pyrite/cli/entry_commands.py:364:assert kb_config is not Nonedisappears underpython -O; usesvc.require_kb(kb_name).entry_commands.py:378:--template --importance 42printsimportance: 42(ran). Since #1570 merged today, a create ondevrefuses importance outside 1 to 10; once you mergedev, either refuse it here the same way or leave the default.- The fragment's first sentence becomes true once item 3 is in.
Not caused by this change: tests/test_mcp_dispatch_off_the_loop.py::test_one_slow_call_does_not_hold_up_another_caller ("the fast call waited 2.38s") is a timing test; the diff touches no MCP or server code. A re-run will clear it.
Not checked: a read-only KB (a create refuses there; the skeleton is printed; say which you intend in the PR body), and hooks that add fields at save.
Recommendation: merge after items 1 to 3.
Fixes #1598.
pyrite create --templatebuilt its skeleton from the core types only, so it ignored the KB named with-k: abacklog_itemskeleton had none of the fields a real create writes, and a type the KB does not declare was not refused.With
-k, the skeleton now reads the same place a create does.KBService.create_template_fieldsbuilds the entry the way_preparebuilds one (_with_declared_fields+build_entry) and reads its declared frontmatter, so the skeleton shows the fields a create of that type in that KB would write, with their defaults. An undeclared type is refused with the same error a create gives (UNDECLARED_TYPE), unless--allow-undeclaredis passed. A-kthat names no KB is refused (KB_NOT_FOUND). Without-k, the skeleton is unchanged.Verified:
create -k proj -t backlog_item --templatenow shows importance 5, kind, status proposed, priority medium, rank 0, effort "", assignee "", matching the file a real create writes.noteskeleton, at its declared default.create -k proj -t nosuch --templaterefuses with UNDECLARED_TYPE, the same error and message as a real create.create -t person --templatewithout-kprints today's skeleton.Tests: new
tests/test_create_template_kb.py(6 tests), all passing. Also rantests/test_cli_commands.py,tests/test_cli_outcome_write_path.py,tests/test_help_texts_render.py, the create-related suites, andextensions/software-kb/tests/, all passing. One pre-existing failure intest_default_output_is_the_result.py(an embed test failing on a missingvec_entrytable) also fails on the pristine tree.